package contacts.service;

import java.util.ArrayList;

import java.util.Collections;
import java.util.List;
import contacts.dao.IRoomDao;
import contacts.dao.IStudentDao;
import contacts.dao.impl.RoomDaoImpl;
import contacts.dao.impl.StudentDaoImpl;
import contacts.po.Student;
import contacts.po.Room;

public class ContactsService {
	private IStudentDao studentDao=new StudentDaoImpl();
	private IRoomDao roomDao=new RoomDaoImpl();
	
	public List<Student> searchById(List<Student> studentList,Student student){
		List<Student> result = new ArrayList<Student>(); //查询结果集
		Collections.sort(studentList);
		int m = -1;
		while ((m = Collections.binarySearch(studentList, student, null)) >= 0) {
			Student stu = studentList.get(m);
			studentList.remove(m);
			result.add(stu);
		}
		return result;
	}
	public void addStudent(Student stu) {
		studentDao.save(stu);	
	}
	public void updateStudent(Student stu) {
		studentDao.update(stu);	
	}
	public void deleteStudent(int id) {
		studentDao.delete(id);
		
	}
	public Student getStudent(int id) {
		return studentDao.get(id);
	}
	
	public List<Student> findAllStudent(){
		return studentDao.findAll();
		
	}
	
	
	public List<Room> searchByroomNo(List<Room> roomList,Room room){
		List<Room> result = new ArrayList<Room>(); //查询结果集
		Collections.sort(roomList);
		int m = -1;
		while ((m = Collections.binarySearch(roomList, room, null)) >= 0) {
			Room room1= roomList.get(m);
			roomList.remove(m);
			result.add(room1);
		}
		return result;
	}
	
	public void addRoom(Room room) {
		roomDao.save(room);	
	}
	
	public void updateRoom(Room room) {
		roomDao.update(room);	
	}
	
	public void deleteRoom(int roomNo) {
		roomDao.delete(roomNo);
	}
	
	public Room getRoom(int roomNo) {
		return roomDao.get(roomNo);
	}
	public List<Room> findAllRoom(){
		return roomDao.findAll();
		
	}
	
}
